package com.focus.xyz.union.pages.frontend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/5/11.
 */
public class WebsiteDetailPage extends BasePage {
    private WebDriver driver;
    private Action action;

    private String url_prefix = "http://union.xyz.cn/union/";

    @FindBy(className = "pro-showcase")
    private List<WebElement> showCases;
    public WebsiteDetailPage(WebDriver driver, Action action) {
        super(driver, action);
        this.action = action;
        PageFactory.initElements(driver,this);
        switchTo(url_prefix);
    }

    public void linkProdDetail(String key) throws Exception{
        if(showCases.size()>0){
            for(WebElement e : showCases){
                WebElement prod = e.findElement(By.xpath("div[contains(@class,'pro-title')]/a"));
                if(key.equals(prod.getText())){
                    action.click(prod);
                    break;
                }
            }
        }
    }
}
